@echo off
chcp 65001 >nul
echo 重启学生信息管理系统微服务...

echo.
echo 1. 停止所有服务...
taskkill /f /im java.exe >nul 2>&1

echo 等待服务完全停止...
timeout /t 5 /nobreak > nul

echo.
echo 2. 启动Eureka注册中心...
start "Eureka Server" cmd /k "cd eureka-server && mvn spring-boot:run"

echo 等待Eureka服务器启动完成...
timeout /t 30 /nobreak > nul

echo 检查Eureka服务器状态...
curl -s http://localhost:8761/actuator/health >nul 2>&1
if %errorlevel% neq 0 (
    echo Eureka服务器可能未完全启动，继续等待...
    timeout /t 15 /nobreak > nul
)

echo.
echo 3. 启动用户服务...
start "User Service" cmd /k "cd user-service && mvn spring-boot:run"

echo 等待用户服务启动...
timeout /t 15 /nobreak > nul

echo.
echo 4. 启动学生服务...
start "Student Service" cmd /k "cd student-service && mvn spring-boot:run"

echo 等待学生服务启动...
timeout /t 15 /nobreak > nul

echo.
echo 5. 启动教师服务...
start "Teacher Service" cmd /k "cd teacher-service && mvn spring-boot:run"

echo 等待教师服务启动...
timeout /t 15 /nobreak > nul

echo.
echo 6. 启动课程服务...
start "Course Service" cmd /k "cd course-service && mvn spring-boot:run"

echo 等待课程服务启动...
timeout /t 15 /nobreak > nul

echo.
echo 7. 启动选课服务...
start "Enrollment Service" cmd /k "cd enrollment-service && mvn spring-boot:run"

echo 等待选课服务启动...
timeout /t 15 /nobreak > nul

echo.
echo 8. 启动成绩服务...
start "Grade Service" cmd /k "cd grade-service && mvn spring-boot:run"

echo 等待成绩服务启动...
timeout /t 15 /nobreak > nul

echo.
echo 9. 启动API网关...
start "Gateway Service" cmd /k "cd gateway-service && mvn spring-boot:run"

echo.
echo 所有服务重启完成！
echo.
echo 访问地址：
echo Eureka控制台: http://localhost:8761
echo API网关: http://localhost:8080
echo.
echo 等待所有服务完全启动后，可以访问Eureka控制台查看服务注册状态
timeout /t 30 /nobreak > nul
echo.
echo 检查服务状态...
echo Eureka服务器: http://localhost:8761
echo 用户服务: http://localhost:8001/actuator/health
echo 学生服务: http://localhost:8002/actuator/health
echo 教师服务: http://localhost:8003/actuator/health
echo 课程服务: http://localhost:8004/actuator/health
echo 选课服务: http://localhost:8005/actuator/health
echo 成绩服务: http://localhost:8006/actuator/health
echo API网关: http://localhost:8080/actuator/health
echo.
pause
